var Observe = (function () {
    var ob;   

    function Obersever() {
        this.events = {};
    }

    Obersever.prototype.emit = function (name, data) {
        if (typeof (this.events[name]) == "undefined") {
            console.log('you did not has events');
            return;
        }

        if (this.events[name].length == 0) {
            console.log('you did not has events');
            return;
        }

        this.events[name].forEach((item, index) => {
            console.log(item);
            item.fn(data);
        });

    }

    Obersever.prototype.on = function (name, callback) {
        // undefined
        if (typeof (this.events[name]) == 'undefined') {
            this.events[name] = []; //create
        }
        var id = this.events[name].length;

        this.events[name].push({
            id: id,
            fn: callback
        });

        return {
            scope: this,
            name: name,
            id: id,
            unsubscribe: function () {
                console.log(this);
                this.scope.unsubscribe(this.name, this.id);
                // Obersever.unsubscribe.apply(null,[this.name,this.callback])
            }
        };
    };

    Obersever.prototype.unsubscribe = function (name, id) {
        this.events[name].splice(id, 1);
        name = null;
        id = null;
        console.log('destory');
    }

    if (typeof (ob) == "undefined") {
        ob = new Obersever();
    }

    return ob;
})();